package com.ruoyi.web.controller.memberManagement;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PointsAcquisitionRule;
import com.ruoyi.system.service.IPointsAcquisitionRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分获取规则（存储消费金额与积分获取比例的规则）Controller
 *
 * @author ruoyi
 * @date 2025-05-15
 */
@Api(tags="积分获取规则")
@RestController
@RequestMapping("/system/pointsAcquisitionRule")
public class PointsAcquisitionRuleController extends BaseController
{
    @Autowired
    private IPointsAcquisitionRuleService pointsAcquisitionRuleService;

    /**
     * 查询积分获取规则列表
     */
    @ApiOperation("查询积分获取规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(PointsAcquisitionRule pointsAcquisitionRule)
    {
        startPage();
        List<PointsAcquisitionRule> list = pointsAcquisitionRuleService.selectPointsAcquisitionRuleList(pointsAcquisitionRule);
        return getDataTable(list);
    }

    /**
     * 导出积分获取规则列表
     */
    @ApiOperation("导出积分获取规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "积分获取规则（存储消费金额与积分获取比例的规则）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointsAcquisitionRule pointsAcquisitionRule)
    {
        List<PointsAcquisitionRule> list = pointsAcquisitionRuleService.selectPointsAcquisitionRuleList(pointsAcquisitionRule);
        ExcelUtil<PointsAcquisitionRule> util = new ExcelUtil<PointsAcquisitionRule>(PointsAcquisitionRule.class);
        util.exportExcel(response, list, "积分获取规则（存储消费金额与积分获取比例的规则）数据");
    }

    /**
     * 获取积分获取规则
     */
    @ApiOperation("获取积分获取规则")
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pointsAcquisitionRuleService.selectPointsAcquisitionRuleById(id));
    }

    /**
     * 新增积分获取规则列表
     */
    @ApiOperation("新增积分获取规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "积分获取规则（存储消费金额与积分获取比例的规则）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PointsAcquisitionRule pointsAcquisitionRule)
    {
        return toAjax(pointsAcquisitionRuleService.insertPointsAcquisitionRule(pointsAcquisitionRule));
    }

    /**
     * 修改积分获取规则列表
     */
    @ApiOperation("修改积分获取规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "积分获取规则（存储消费金额与积分获取比例的规则）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PointsAcquisitionRule pointsAcquisitionRule)
    {
        return toAjax(pointsAcquisitionRuleService.updatePointsAcquisitionRule(pointsAcquisitionRule));
    }

    /**
     * 删除积分获取规则列表
     */
    @ApiOperation("删除积分获取规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "积分获取规则（存储消费金额与积分获取比例的规则）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointsAcquisitionRuleService.deletePointsAcquisitionRuleByIds(ids));
    }
}
